﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using YABE.Validators;

namespace YABE.Models
{
    public partial class Post:IRuleEntity
    {
        //Validations can happen here
        public List<RuleViolation> GetRuleViolations()
        {
            List<RuleViolation> validationIssues = new List<RuleViolation>();
            RuleViolation titleValidation = CheckTitleValidation();
            if(titleValidation != null)
                validationIssues.Add(titleValidation);

            RuleViolation bodyValidation = CheckBodyValidation();
            if (bodyValidation != null)
                validationIssues.Add(bodyValidation);
            return validationIssues;

        }

        //check for post title empty
        public RuleViolation CheckTitleValidation()
        {
            RuleViolation titleValidation = null;
            if(String.IsNullOrEmpty(this.Title) || (this.Title.Trim().Length==0))
            {
                string PostTitleEmpty = Resources.ErrorMessages.PostTitleEmpty;
                titleValidation = new RuleViolation("PostTitleEmpty",String.Empty,PostTitleEmpty);
            }
            return titleValidation;
        }

        //check for post body empty
        public RuleViolation CheckBodyValidation()
        {
            RuleViolation bodyValidation = null;
            if(String.IsNullOrEmpty(this.Body) || (this.Body.Trim().Length==0))
            {
                string PostBodyEmpty = Resources.ErrorMessages.PostBodyEmpty;
                bodyValidation = new RuleViolation("PostBodyEmpty",String.Empty,PostBodyEmpty);
            }

            return bodyValidation;
        }

		public string Url
		{
			get
			{
				return string.Format("{2}/{0}/{1}", this.Created.ToString("yyyy/MM/dd"), this.Title.ToString().Replace(' ', '-'), Modules.Helpers.WebHelper.SiteRoot);
			}
		}
    }
}
